package edu.nus.mtech.sem1.ca.auth;

import edu.nus.mtech.sem1.ca.utils.TelephonyUtils;


/**
 * Holds User data
 *
 */
public class User {
	
	private String userName;
	private String password;
	//Multiple roles or role inheritance aren't allowed for this version of the program
	private UserRole userRole;
	
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public UserRole getUserRole() {
		return userRole;
	}
	public void setUserRole(UserRole userRole) {
		this.userRole = userRole;
	}
	
	@Override
	public boolean equals(Object userObj) {
		boolean allResult=false;
		
		if (userObj !=null && userObj instanceof User){
			if (((User) userObj).getPassword().equals(password)){
				allResult=true;
			}
			if (((User) userObj).getUserName().equals(userName)){
				allResult=allResult && true;
			}
			if (((User) userObj).getUserRole().equals(userRole)){
				allResult=allResult && true;
			}
		}
		return allResult;
	}
	
	@Override
	public String toString() {
		return(userName+"::"+password+"::"+userRole.toString());
	}
	
	@Override
	public int hashCode() {
		
		int hashCode=(TelephonyUtils.getHashCode(userName)*73)+TelephonyUtils.getHashCode(password)+TelephonyUtils.getHashCode(userRole);
		
		return hashCode;
	}
}
